{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "11f2776c-89f5-4816-a2b2-d8b3598defc9",
   "metadata": {},
   "source": [
    "# 顺序执行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "9b84300d-5224-470d-b860-8a013604c3bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fc63c42a19824d7b86a862d28a27704b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(height=600, width=600)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import ipyturtle3 as turtle\n",
    "import math\n",
    "from ipyturtle3 import hold_canvas\n",
    "myCanvas=turtle.Canvas(width=600,height=600)\n",
    "display(myCanvas)\n",
    "myTS=turtle.TurtleScreen(myCanvas)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "9c1f0054-a446-43df-9dfe-5dd0714cfdea",
   "metadata": {},
   "outputs": [],
   "source": [
    "myTS.clear()\n",
    "# myTS.bgcolor(\"lightgreen\")\n",
    "bob=turtle.Turtle(myTS)\n",
    "# jess=turtle.Turtle(myTS,isHolonomic=True)\n",
    "jess.shape(\"square\")\n",
    "bob.shape(\"turtle\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "9a213e4a-224e-4284-ba43-5bd65b1cffe6",
   "metadata": {},
   "outputs": [],
   "source": [
    "myTS.delay(0)\n",
    "for c in range(1000):\n",
    "    bob.forward(1/(400*math.pi))\n",
    "    bob.left(1/(8000*math.pi))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "c0244917-4da2-40d4-b438-10eca6335397",
   "metadata": {},
   "outputs": [],
   "source": [
    "myTS.delay(0)\n",
    "# Usual turtle Non-holonomic example\n",
    "b=1\n",
    "colors = ['red','purple', 'blue', 'green']\n",
    "\n",
    "for i in range(100):\n",
    "    bob.right(5)\n",
    "    for a in range(4):\n",
    "        with(hold_canvas(myCanvas)):\n",
    "            bob.pencolor(colors[a%4])\n",
    "            bob.forward(b)\n",
    "            bob.left(90)\n",
    "            b+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "641a2864-4e70-49ab-bd1f-7f9895a5376b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Holonomic\n",
    "jess.moveleft(200)\n",
    "jess.moveup(100)\n",
    "jess.moveright(100)\n",
    "jess.movedown(100)\n",
    "jess.turnright(45)\n",
    "jess.turn(-45)\n",
    "jess.distance_at_angle(50,45)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "55983bc5-34ae-4e0d-bc34-55c3151cff03",
   "metadata": {},
   "outputs": [],
   "source": [
    "myTS.clear()\n",
    "\n",
    "# Rainbow benzene\n",
    "colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']\n",
    "t = turtle.Turtle(myTS)\n",
    "myTS.bgcolor('black')\n",
    "for x in range(50):\n",
    "    with(hold_canvas(myCanvas)):\n",
    "        t.pencolor(colors[x%6])\n",
    "        t.width(x//100 + 1)\n",
    "        t.forward(x)\n",
    "        t.left(59)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20fba923-1701-4065-9497-dd263ba08537",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
